<?php
class DealModel extends CI_Model
{   
    function getList($curpage = 1, $pagesize = 20, $city_id, $category_id = -1, $subloc = '', $pricerange = 1)
    {   
    	$pagesize = 20;
    	$from = ($curpage - 1) * $pagesize + 1;
    	if(!intval($pricerange)) $pricerange = 1;
    	$params = array(
    		array($category_id),
    		array($pricerange),
    		array($city_id),
    		array($subloc),
    		array($from),
    		array($pagesize),
    	);
    	/**
    	 * params as:
	     * @CategoryID int=-1,@PriceRangeID int=1,@CityID int=1,@StreetName varchar(100)='',@SubLoc varchar(100)='',@FromNum int=1,@DealCount int=10,@OrderType int=0	    
    	 */
	    return $this->sqlsrv_sp_driver->result('getDealListForWeb(?,?,?,,?,?,?)', $params);
    }
    
    function getPriceRanges()
    {
    	return $this->sqlsrv_sp_driver->result('getPriceRangeList');
    }    
    
    function get($deal_id)
    {
    	$params = array(
    		array($deal_id, SQLSRV_PARAM_IN),
    	);
    	$result = $this->sqlsrv_sp_driver->result('getSingleDeal(?)',$params);   
    	if(count($result))
    	{
    		return $result[0];
    	}
    	return false; 	
    }
    
    function getRelatedShops($deal_id)
    {
    	$params = array(
    		array($deal_id, SQLSRV_PARAM_IN),
    	);
    	return $this->sqlsrv_sp_driver->result('getSingleDealShops(?)',$params);
    }
}